package server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) {
        try (ServerSocket serverSocket = new ServerSocket(12345)) {
            System.out.println("服务器启动，等待客户端连接...");
            ContactManager contactManager = new ContactManager();

            // 持续接受客户端连接
            while (true) {
                Socket clientSocket = serverSocket.accept();
                System.out.println("客户端连接成功: " + clientSocket.getInetAddress() + ":" + clientSocket.getPort());
                // 每个客户端连接由一个新的线程处理
                new Thread(new ResponseHandler(clientSocket, contactManager)).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
